package ink.tiptop.controller;

import ink.tiptop.persist.domain.entity.ZjfAuthUserInfoEntity;
import ink.tiptop.dto.req.auth.*;
import ink.tiptop.common.domain.rsp.Response;
import ink.tiptop.common.domain.rsp.SucceedResponse;
import ink.tiptop.service.ZjfAuthUserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import ink.tiptop.utils.JSON;
/**
 * 用于用户登录的信息(ZjfAuthUserInfoEntity)表控制层
 *
 * @author makejava
 * @since 2020-06-21 20:35:17
 */
@Api("用户管理API")
@RestController
@RequestMapping("zjfAuthUserInfo")
@Slf4j
public class UserController {
    /**
     * 服务对象
     */
    @Resource
    private ZjfAuthUserInfoService zjfAuthUserInfoService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation("查询单一用户")
    @GetMapping("selectOne")
    @ResponseBody
    public ZjfAuthUserInfoEntity selectOne(Integer id) {
        return this.zjfAuthUserInfoService.queryById(id);
    }

    @ApiOperation("添加用户")
    @PostMapping("add")
    public Response add(@RequestBody AddZjfAuthUserInfoRequest request) {
        log.info("添加用户信息接口:{}", JSON.toJSONString(request));
        return zjfAuthUserInfoService.add(request);
    }

    @ApiOperation("批量删除用户")
    @PostMapping("delete")
    public Response delete(@RequestBody DeleteZjfAuthUserInfoRequest request) {
        log.info("删除用户信息接口:{}", JSON.toJSONString(request));
        return SucceedResponse.SUCCEED;
    }

    @ApiOperation("更新用户信息")
    @PostMapping("update")
    public Response update(@RequestBody UpdateAddZjfAuthUserInfoRequest request) {
        log.info("更新用户信息接口:{}", JSON.toJSONString(request));
        return SucceedResponse.SUCCEED;
    }

    @ApiOperation("列表查询用户信息")
    @PostMapping("list")
    public Response list(@RequestBody QueryZjfAuthUserInfoRequest request) {
        log.info("查询用户信息接口:{}", JSON.toJSONString(request));
        return SucceedResponse.SUCCEED;
    }

    @Autowired
    private ZjfAuthUserInfoService authUserInfoService;

    @ApiOperation("用户登录")
    @PostMapping("login")
    @ResponseBody
    public Response login(@RequestBody @Valid LoginZjfAuthUserInfoRequest request) {
        log.info("用户登陆接口:{}", JSON.toJSONString(request));
        return authUserInfoService.login(request);
    }

    @ApiOperation("用户登出")
    @PostMapping("logout")
    @ResponseBody
    public Response logout() {
        log.info("用户登出接口");
        return authUserInfoService.logout();
    }


    @ApiOperation("修改用户密码")
    @PostMapping("changePassword")
    public Response changePassword(@RequestBody ChangePasswordZjfAuthUserInfoRequest request) {
        log.info("修改用户密码接口:{}", JSON.toJSONString(request));
        return authUserInfoService.changePasswordByUserName(request);
    }

}